#ifndef STX_ALGORITHM_MAX_ELEMENT_HPP
#define STX_ALGORITHM_MAX_ELEMENT_HPP

#include <stx/algorithm/common.hpp>

namespace stx {

template <class ForwardIterator, class Compare>
inline ForwardIterator
max_element(ForwardIterator first, ForwardIterator last, Compare comp)
{
    if (first != last) {
        ForwardIterator i = first;
        while (++i != last) {
            if (comp(*first, *i)) {
                first = i;
            }
        }
    }
    return first;
}

template <class ForwardIterator>
inline ForwardIterator
max_element(ForwardIterator first, ForwardIterator last)
{
    return stx::max_element(
        first,
        last,
        stx::less<typename std::iterator_traits<ForwardIterator>::value_type>());
}

} // namespace stx

#endif // STX_ALGORITHM_MAX_ELEMENT_HPP
